home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr49 / 279_01.zip / ROOK.R < prev    next >
Text File  |  1993-04-01  |  2KB  |  84 lines

  1. /* rook.r  -  scans the battlefield like a rook, i.e., only 0,90,180,270 */
  2. /* move horizontally only, but looks horz and vertically */
  3.  
  4. int course;
  5. int boundary;
  6. int d;
  7.  
  8. main()
  9. {
  10.   int y;
  11.  
  12.   /* move to center of board */
  13.   if (loc_y() < 500) {
  14.     drive(90,70);                /* start moving */
  15.     while (loc_y() - 500 < 20 && speed() > 0)    /* stop near center */
  16.       ;
  17.   } else {
  18.     drive(270,70);                /* start moving */
  19.     while (loc_y() - 500 > 20 && speed() > 0)    /* stop near center */
  20.       ;
  21.   }
  22.   drive(y,0);
  23.  
  24.   /* initialize starting parameters */
  25.   d = damage();
  26.   course = 0;
  27.   boundary = 995;
  28.   drive(course,30);
  29.  
  30.   /* main loop */
  31.  
  32.   while(1) {
  33.  
  34.     /* look all directions */
  35.     look(0);
  36.     look(90);
  37.     look(180);
  38.     look(270);
  39.  
  40.     /* if near end of battlefield, change directions */
  41.     if (course == 0) {
  42.       if (loc_x() > boundary || speed() == 0) 
  43.     change();
  44.     }
  45.     else {
  46.       if (loc_x() < boundary || speed() == 0) 
  47.     change();
  48.     }
  49.   }
  50.     
  51. }
  52.  
  53. /* look somewhere, and fire cannon repeatedly at in-range target */
  54. look(deg)
  55. int deg;
  56. {
  57.   int range;
  58.  
  59.   while ((range=scan(deg,2)) > 0 && range <= 700)  {
  60.     drive(course,0);
  61.     cannon(deg,range);
  62.     if (d+20 != damage()) {
  63.       d = damage();
  64.       change();
  65.     }
  66.   }
  67. }
  68.  
  69.  
  70. change() {
  71.   if (course == 0) {
  72.     boundary = 5;
  73.     course = 180;
  74.   } else {
  75.     boundary = 995;
  76.     course = 0;
  77.   }
  78.   drive(course,30);
  79. }
  80.  
  81.  
  82. /* end of rook.r */
  83.  
  84.